package com.bsoft.gol.editor.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsoft.gol.editor.service.EditorAnswerApi;
import ctd.util.JSONUtils;
import com.bsoft.gol.editor.dao.*;
import com.bsoft.gol.editor.editor.*;
import com.bsoft.gol.editor.editor.response.QueryAnswerListResponse;
import com.bsoft.gol.editor.editor.response.QueryEditorUserInfoListResponse;
import hcn.sync.core.util.StringUtils;
import hcn.util.BaseResponse;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.bsoft.gol.editor.utils.BaseManage;
import com.bsoft.gol.editor.utils.CommonUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 答案表
 */
@Service("editorAnswerApi")
@Transactional
public class EditorAnswerApiImpl extends BaseManage implements EditorAnswerApi {
    private static Logger logger = LoggerFactory.getLogger(EditorAnswerApiImpl.class);

    @Autowired
    private EditorUserInfoDAO editorUserInfoDAO;
    @Autowired
    private EditorAnswerDAO editorAnswerDAO;
    @Autowired
    private EditorQuestionnaireTitleDAO editorQuestionnaireTitleDAO;
    @Autowired
    private EditorQuestionnaireDAO editorQuestionnaireDAO;
    @Autowired
    private EditorTitleOptionDAO editorTitleOptionDAO;
    @Autowired
    private ControlReportEntityDAO controlReportEntityDAO;


    /**
     * 答案保存
     *
     * @param req
     * @return
     */
    @Override
    public Map<String, Object> saveBatch(EditorUserInfo req) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ParseException {
        BaseResponse<String> baseResponse = new BaseResponse();
        Map<String, Object> resMap = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        EditorQuestionnaire editorQuestionnaire = editorQuestionnaireDAO.get(req.getQuestionnaireId());
        List<EditorAnswer> editorAnswerList = new ArrayList();
        if (req.getUserInfoId() != null && req.getUserInfoId().length() != 0 && !req.getUserInfoId().equals("null")) {
            //req.getUserInfoId() 验证
            EditorUserInfo editorUserInfo = editorUserInfoDAO.get(req.getUserInfoId());

            if (editorUserInfo != null) {
                Calendar c1 = Calendar.getInstance();
                Calendar c2 = Calendar.getInstance();
                c1.setTime(editorUserInfo.getWriteTime());
                c2.setTime(new Date());
                int year1 = c1.get(Calendar.YEAR);
                int month1 = c1.get(Calendar.MONTH) + 1;
                int day1 = c1.get(Calendar.DAY_OF_MONTH);
                int year2 = c2.get(Calendar.YEAR);
                int month2 = c2.get(Calendar.MONTH) + 1;
                int day2 = c2.get(Calendar.DAY_OF_MONTH);
                Boolean editorFlag1 = false;
                Boolean editorFlag2 = false;

                if (editorUserInfo.getAnswerState() == 2) {
                    if (CommonUtils.isNull(editorQuestionnaire.getIfToday()) && CommonUtils.isNull(editorQuestionnaire.getEffectiveTime())) {
                        resMap.put("code", ResultCode.PARAMETERS_NOTLEGAL);
                        resMap.put("message", "表单未设置有效期，无法修改");
                        return resMap;
                    }

                    if (CommonUtils.isNotNull(editorQuestionnaire.getIfToday())) {
                        if (editorQuestionnaire.getIfToday() == 1 && (day1 == day2 && year1 == year2 && month1 == month2)) {
                            editorFlag1 = true;
                        }
                    }
                    if (CommonUtils.isNotNull(editorQuestionnaire.getEffectiveTime())) {
                        c1.add(Calendar.HOUR, editorQuestionnaire.getEffectiveTime());
                        if (c2.before(c1)) {
                            editorFlag2 = true;
                        }
                    }
                    if (editorFlag1 == true || editorFlag2 == true) {

                    } else {
                        resMap.put("code", ResultCode.PARAMETERS_NOTLEGAL);
                        resMap.put("message", "答案已过有效期，无法修改");
                        return resMap;
                    }
                }


                ctd.util.BeanUtils.copy(req, editorUserInfo);
                editorUserInfoDAO.update(editorUserInfo);
                //删除答案表数据
                editorAnswerDAO.removeByUserInfoId(req.getUserInfoId());


            } else {

                resMap.put("code", ResultCode.PARAMETERS_NOTLEGAL);
                resMap.put("message", "传入参数错误");
                return resMap;
            }
        } else {

            Date now = new Date();
            req.setWriteTime(now);
            req.setUserInfoId(UUID.randomUUID().toString());
            editorUserInfoDAO.save(req);
        }
        logger.info(req.getUserInfoId());

        //是否异常 1是2否
        String answerAbnormal = "2";
        //总分
        BigDecimal totalGrade = new BigDecimal(0.00);

        //批量添加答案
        for (EditorAnswer editorAnswer : req.getAnswers()) {
            EditorAnswer answerWithBLOBs = new EditorAnswer();
            if (CommonUtils.isNull(editorAnswer.getTitleId())
                    || CommonUtils.isNull(editorAnswer.getOptionType())) {
                resMap.put("code", ResultCode.PARAMETERS_EMPTY);
                resMap.put("message", "传入参数不能为空");
                return resMap;
            }
            answerWithBLOBs.setAnswerId(UUID.randomUUID().toString());
            answerWithBLOBs.setQuestionnaireId(req.getQuestionnaireId());
            answerWithBLOBs.setUserInfoId(req.getUserInfoId());
            answerWithBLOBs.setTitleId(editorAnswer.getTitleId());
            answerWithBLOBs.setOptionId(editorAnswer.getOptionId());
            answerWithBLOBs.setOptionType(editorAnswer.getOptionType());
            answerWithBLOBs.setAnswerContent(editorAnswer.getAnswerContent());
            answerWithBLOBs.setAnswerDesc(editorAnswer.getAnswerDesc());
            answerWithBLOBs.setOptionNotes(editorAnswer.getOptionNotes());
            EditorQuestionnaireTitle editorQuestionnaireTitle = editorQuestionnaireTitleDAO.get(editorAnswer.getTitleId());
            List<String> optionIds = new ArrayList<>();
            if (CommonUtils.isNotEmpty(editorAnswer.getOptionId())) {
                optionIds = Arrays.asList(editorAnswer.getOptionId().split(","));
                List<EditorTitleOption> editorTitleOptionResList = editorTitleOptionDAO.queryEditorTitleOptionByOptionIds(optionIds);
                for (EditorTitleOption editorTitleOption : editorTitleOptionResList) {
                    if (CommonUtils.isNotNull(editorTitleOption.getOptionAbnormal()) && editorTitleOption.getOptionAbnormal() == 1) {
                        answerWithBLOBs.setAnsweAbnormal((byte) 1);
                        answerAbnormal = "1";
                        editorAnswerDAO.updateEditorAnswerIfAbnormal(req.getUserInfoId());
                        editorUserInfoDAO.updateEditorAnswerIfAbnormal(req.getUserInfoId());
                    }
                    answerWithBLOBs.setOptionNotes(editorTitleOption.getOptionNotes());
                }
            }

            if (CommonUtils.isNotNull(editorQuestionnaireTitle.getTitleReturn()) && editorQuestionnaireTitle.getTitleReturn() == 1) {
                editorAnswerList.add(answerWithBLOBs);
            }

            //有分数标志
            boolean haveGradeFlag = false;
            BigDecimal grade = new BigDecimal(0.00);
            if (editorQuestionnaireTitle != null) {
                if (editorQuestionnaireTitle.getWidgetType() == 1 || editorQuestionnaireTitle.getWidgetType() == 3 || editorQuestionnaireTitle.getWidgetType() == 14 || editorQuestionnaireTitle.getWidgetType() == 26 || editorQuestionnaireTitle.getWidgetType() == 29 || editorQuestionnaireTitle.getWidgetType() == 30) {
                    //根据单个选项id获取选项分值
                    if (CommonUtils.isNotEmpty(optionIds)) {
                        List<EditorTitleOption> options = editorTitleOptionDAO.queryEditorTitleOptionByOptionIds(optionIds);
                        if (options.size() > 0) {
                            if (options.get(0).getOptionGrade() != null) {
                                haveGradeFlag = true;
                                grade = grade.add(options.get(0).getOptionGrade());
                            }
                        }
                    }
                } else if (editorQuestionnaireTitle.getWidgetType() == 2 || editorQuestionnaireTitle.getWidgetType() == 7) {
                    //根据多个选项id获取选项分值
                    if (CommonUtils.isNotEmpty(optionIds)) {
                        List<EditorTitleOption> options = editorTitleOptionDAO.queryEditorTitleOptionByOptionIds(optionIds);
                        for (EditorTitleOption option : options) {
                            if (option.getOptionGrade() != null) {
                                haveGradeFlag = true;
                                grade = grade.add(option.getOptionGrade());
                            }
                        }
                    }
                } else if (editorQuestionnaireTitle.getWidgetType() == 6 && "99".equals(editorQuestionnaireTitle.getWriteTips())) {
                    haveGradeFlag = true;
                    if (CommonUtils.isNotEmpty(editorQuestionnaireTitle.getStartMark())) {
                        double startMark = Double.valueOf(editorQuestionnaireTitle.getStartMark());
                        String answerContent = editorAnswer.getAnswerContent();
                        Pattern pattern = Pattern.compile("^(\\-|\\+)?\\d+(\\.\\d+)?$");
                        Matcher isNum = pattern.matcher(answerContent);
                        if (CommonUtils.isNotEmpty(answerContent) && isNum.matches()) {
                            double answer = Double.valueOf(answerContent);
                            double i = startMark * answer;
                            grade = grade.add(new BigDecimal(i));
                        } else {
                            grade = grade.add(new BigDecimal(0));
                        }
                    }
                }
                //检查记录
                else if (editorQuestionnaireTitle.getWidgetType() == 21 ||
                        //检验记录
                        editorQuestionnaireTitle.getWidgetType() == 22 ||
                        //门诊情况
                        editorQuestionnaireTitle.getWidgetType() == 23 ||
                        //住院情况
                        editorQuestionnaireTitle.getWidgetType() == 24 ||
                        //手术操作
                        editorQuestionnaireTitle.getWidgetType() == 25 ||
                        //病历记录
                        editorQuestionnaireTitle.getWidgetType() == 34 ||
                        //病理记录
                        editorQuestionnaireTitle.getWidgetType() == 36 ||
                        //评估评分
                        editorQuestionnaireTitle.getWidgetType() == 37 ||
                        //用药记录
                        editorQuestionnaireTitle.getWidgetType() == 38 ||
                        //门诊处置
                        editorQuestionnaireTitle.getWidgetType() == 39) {

                    if (CommonUtils.isNotEmpty(editorAnswer.getAnswerContent())) {
                        JSONArray jsonArray = JSONArray.parseArray(editorAnswer.getAnswerContent());
                        for (int i = 1; i < jsonArray.size(); i++) {
                            JSONArray jsonArray2 = jsonArray.getJSONArray(i);
                            ControlReportEntity controlReportEntity = new ControlReportEntity();
                            ControlReportEntityRequest controlReportEntityRequest = new ControlReportEntityRequest();

                            for (int j = 1; j < jsonArray2.size(); j++) {
                                EditorTitleOption option = JSONObject.toJavaObject(jsonArray2.getJSONObject(j), EditorTitleOption.class);
                                EditorTitleOption option2 = JSONObject.toJavaObject(jsonArray.getJSONArray(0).getJSONObject(j), EditorTitleOption.class);

                                if (CommonUtils.isNotEmpty(option.getOptionContent())) {
                                    try {
                                        String optionExplain = option2.getOptionExplain();
                                        if (CommonUtils.isNotEmpty(optionExplain)) {
                                            if (optionExplain.length() == 1) {
                                                optionExplain = optionExplain.substring(0, 1).toUpperCase();
                                            } else {
                                                optionExplain = optionExplain.substring(0, 1).toUpperCase() + optionExplain.substring(1);
                                            }
                                        }

                                        Type type = controlReportEntityRequest.getClass().getDeclaredMethod("get" + optionExplain).getGenericReturnType();
                                        if ("class java.lang.String".equals(type.toString()) ||
                                                "class java.lang.Double".equals(type.toString()) ||
                                                "class java.lang.Integer".equals(type.toString()) ||
                                                "class java.math.BigDecimal".equals(type.toString())) {

                                            Method m1 = null;
                                            if ("class java.lang.String".equals(type.toString())) {
                                                //若是该字段是剂量单位，并且剂量单位不为空，那么就不赋值，跳过
                                                if ("DosageUnit".equals(optionExplain) && CommonUtils.isNotEmpty(controlReportEntityRequest.getDosageUnit())) {
                                                    continue;
                                                } else {
                                                    m1 = controlReportEntityRequest.getClass().getDeclaredMethod("set" + optionExplain, String.class);
                                                    m1.setAccessible(true);
                                                    m1.invoke(controlReportEntityRequest, option.getOptionContent());
                                                }
                                            }
                                            if ("class java.lang.Double".equals(type.toString())) {
                                                //由于表单编辑器输入答案分两种，自动引入和手动输入，手动输入没有输入单位的抵挡，所以剂量这个字段有可能有个包含中文或英文
                                                //若是该字段是剂量，并且剂量不是纯数字，包含除中文之外的，那么剂量字段就不赋值，给剂量单位赋值
                                                if ("OnceDosage".equals(optionExplain)) {
                                                    if (CommonUtils.isNotEmpty(option.getOptionContent())) {
                                                        Pattern pattern = Pattern.compile("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}");
                                                        Matcher isNum = pattern.matcher(option.getOptionContent());

                                                        if (!isNum.matches()) {
                                                            controlReportEntityRequest.setDosageUnit(option.getOptionContent());
                                                        }
                                                    }
                                                } else {
                                                    m1 = controlReportEntityRequest.getClass().getDeclaredMethod("set" + optionExplain, Double.class);
                                                    m1.setAccessible(true);
                                                    m1.invoke(controlReportEntityRequest, Double.valueOf(option.getOptionContent()));
                                                }
                                            }
                                            if ("class java.lang.Integer".equals(type.toString())) {
                                                m1 = controlReportEntityRequest.getClass().getDeclaredMethod("set" + optionExplain, Integer.class);
                                                m1.setAccessible(true);
                                                m1.invoke(controlReportEntityRequest, Integer.valueOf(option.getOptionContent()));
                                            }
                                            if ("class java.math.BigDecimal".equals(type.toString())) {
                                                m1 = controlReportEntityRequest.getClass().getDeclaredMethod("set" + optionExplain, BigDecimal.class);
                                                m1.setAccessible(true);
                                                m1.invoke(controlReportEntityRequest, new BigDecimal(option.getOptionContent()));
                                            }

                                            if ("TestResult".equals(optionExplain)) {
                                                controlReportEntityRequest.setItemContent(option.getOptionContent());
                                            }
                                            if ("ExamDescript".equals(optionExplain) && editorQuestionnaireTitle.getWidgetType() == 21) {
                                                controlReportEntityRequest.setExamDescript(option.getOptionContent());
                                                controlReportEntityRequest.setItemContent(option.getOptionContent());
                                            }
                                        } else {
                                            SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
                                            //手填的日期没有时分秒
                                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                            SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                            String oldDate = option.getOptionContent().replace("Z", " UTC");
                                            Date date;
                                            Date date2;
                                            try {
                                                date = utcFormat.parse(oldDate);

                                            } catch (Exception e) {
                                                date = dateFormat.parse(oldDate);
                                            }
                                            String date1 = defaultFormat.format(date);
                                            date2 = defaultFormat.parse(date1);

                                            Method m1 = controlReportEntityRequest.getClass().getDeclaredMethod("set" + optionExplain, Date.class);
                                            m1.setAccessible(true);
                                            m1.invoke(controlReportEntityRequest, date2);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                            Date now = new Date();
                            controlReportEntity.setAnswerTime(now);
                            controlReportEntity.setUserInfoId(req.getUserInfoId());
                            controlReportEntity.setTitleId(answerWithBLOBs.getTitleId());

                            setControlReportEntity(controlReportEntityRequest, controlReportEntity);

                            String subassemblyType;
                            switch (editorQuestionnaireTitle.getWidgetType()) {
                                case 21://检查记录
                                    subassemblyType = "1";
                                    break;
                                case 22://检验记录
                                    subassemblyType = "2";
                                    break;
                                case 23://门诊情况
                                    subassemblyType = "3";
                                    break;
                                case 24://住院情况
                                    subassemblyType = "4";
                                    break;
                                case 25://手术操作
                                    subassemblyType = "5";
                                    break;
                                case 34://病历记录
                                    subassemblyType = "6";
                                    break;
                                case 37://评估评分
                                    subassemblyType = "7";
                                    break;
                                case 38://用药记录
                                    subassemblyType = "8";
                                    break;
                                case 39://门诊处置
                                    subassemblyType = "9";
                                    break;
                                default:
                                    subassemblyType = "";
                            }
                            controlReportEntity.setSubassemblyType(subassemblyType);

                            controlReportEntity.setReportId(UUID.randomUUID().toString());
                            if (req.getUserInfoId() != null && controlReportEntity.getItemId() != null) {
                                ControlReportEntity controlReportEntityOld = controlReportEntityDAO.getControlReportByUserId(req.getUserInfoId(), editorAnswer.getTitleId(), controlReportEntity.getItemId());
                                if (controlReportEntityOld != null) {
                                    controlReportEntity.setReportId(controlReportEntityOld.getReportId());
                                    controlReportEntityDAO.remove(controlReportEntityOld.getReportId());
                                }

                            }
                            controlReportEntity.setReportContent(JSONUtils.writeValueAsString(controlReportEntity));
                            controlReportEntityDAO.save(controlReportEntity);
                        }
                    }
                }
            }

            if (haveGradeFlag) {
                answerWithBLOBs.setGrade(grade);
                totalGrade = totalGrade.add(grade);
            }
            editorAnswerDAO.save(answerWithBLOBs);
        }

        EditorUserInfo editorUserInfo = editorUserInfoDAO.get(req.getUserInfoId());
        editorUserInfo.setTotalGrade(totalGrade);
        editorUserInfoDAO.update(editorUserInfo);
        resMap.put("code", ResultCode.SUCCESS);
        data.put("editorAnswerList", editorAnswerList);
        data.put("userInfoId", req.getUserInfoId());
        data.put("answerAbnormal", answerAbnormal);
        data.put("totalGrade", totalGrade);
        resMap.put("data", data);

        return resMap;
    }


    public void setControlReportEntity(ControlReportEntityRequest controlReportEntityRequest, ControlReportEntity controlReportEntity) {
        controlReportEntity.setItemId(controlReportEntityRequest.getTestCode());
        controlReportEntity.setItemName(controlReportEntityRequest.getTestName());
        if (CommonUtils.isEmpty(controlReportEntity.getItemId())) {
            controlReportEntity.setItemId(controlReportEntityRequest.getExamItemCode());
        }
        if (CommonUtils.isEmpty(controlReportEntity.getItemName())) {
            controlReportEntity.setItemName(controlReportEntityRequest.getExamItemName());
        }
        controlReportEntity.setItemContent(controlReportEntityRequest.getItemContent());
        controlReportEntity.setVisitTime(controlReportEntityRequest.getOutpatientDate());
        controlReportEntity.setDepartmentId(controlReportEntityRequest.getDepartmentId());
        controlReportEntity.setDepartmentName(controlReportEntityRequest.getDepartmentName());
        controlReportEntity.setDiagnosisId("");
        controlReportEntity.setDiagnosisName("");
        controlReportEntity.setDoctorId(controlReportEntityRequest.getDoctorId());
        controlReportEntity.setDoctorName(controlReportEntityRequest.getDoctorName());
        controlReportEntity.setDischargeDiagnosisCode("");
        controlReportEntity.setDischargeDiagnosisName(controlReportEntityRequest.getChuyuan());
        //住院赋值
        controlReportEntity.setBeAdmissionTime(controlReportEntityRequest.getBeAdmissionTime());
        controlReportEntity.setDischargeTime(controlReportEntityRequest.getDischargeTime());
        controlReportEntity.setSfzh(controlReportEntityRequest.getSfzh());
        controlReportEntity.setReportTime(controlReportEntityRequest.getReportTime());
        controlReportEntity.setIfSynchro(controlReportEntityRequest.getIfSynchro());
        controlReportEntity.setDiagnosisType("");
        controlReportEntity.setDiagnosisList(controlReportEntityRequest.getDiagnosisList());
        //检查赋值
        controlReportEntity.setExamTypeCode(controlReportEntityRequest.getExamTypeCode());
        controlReportEntity.setExamTypeName(controlReportEntityRequest.getExamTypeName());
        controlReportEntity.setExamPartCode(controlReportEntityRequest.getExamPartCode());
        controlReportEntity.setExamPartName(controlReportEntityRequest.getExamPartName());
        controlReportEntity.setDiagnoseName(controlReportEntityRequest.getExamDiagnosis());
        controlReportEntity.setImageNo(controlReportEntityRequest.getImageNo());
        controlReportEntity.setExamPhotoId(controlReportEntityRequest.getImgList());
        //药品赋值
        controlReportEntity.setPrescriptionId("");
        controlReportEntity.setDrugsNumber(controlReportEntityRequest.getDrugsNumber());
        controlReportEntity.setDrugName(controlReportEntityRequest.getDrugName());
        controlReportEntity.setDrugUsePathwaysCode(controlReportEntityRequest.getDrugUsePathwaysCode());
        controlReportEntity.setDrugUsePathwaysName(controlReportEntityRequest.getDrugUsePathwaysName());
        controlReportEntity.setDrugUsingRate(controlReportEntityRequest.getDrugUsingRate());
        controlReportEntity.setDrugUsingRateName(controlReportEntityRequest.getDrugUsingRateName());
        controlReportEntity.setOnceDosage(controlReportEntityRequest.getOnceDosage());
        controlReportEntity.setDosageUnit(controlReportEntityRequest.getDosageUnit());
        controlReportEntity.setMedicineDays(controlReportEntityRequest.getMedicineDays());
        controlReportEntity.setDrugSendNumber(controlReportEntityRequest.getDrugSendNumber());
        controlReportEntity.setPrice(controlReportEntityRequest.getPrice());
        controlReportEntity.setDrugstoreUnit(controlReportEntityRequest.getDrugstoreUnit());
        controlReportEntity.setDrugSpecifications(controlReportEntityRequest.getDrugSpecifications());
        controlReportEntity.setOrganizationId(controlReportEntityRequest.getOrganizationId());
        controlReportEntity.setOrganizationName(controlReportEntityRequest.getOrganizationName());
        //检验赋值
        controlReportEntity.setSpecimenTypeId(controlReportEntityRequest.getSampleTypeCode());
        controlReportEntity.setSpecimenTypeName(controlReportEntityRequest.getSampleTypeName());
        controlReportEntity.setSampleTestTime(controlReportEntityRequest.getReportTime());
        controlReportEntity.setResult(controlReportEntityRequest.getItemContent());
        controlReportEntity.setRefRange(controlReportEntityRequest.getResultCode());
        //手术赋值
        controlReportEntity.setOperativeName(controlReportEntityRequest.getOperationName());
        controlReportEntity.setOperativeRecordId(controlReportEntityRequest.getOperationRecordId());
        controlReportEntity.setOperativeCode(controlReportEntityRequest.getOperationCode());
        controlReportEntity.setOperativeTime(controlReportEntityRequest.getStartTime());
        controlReportEntity.setAnesthesiaWayCode(controlReportEntityRequest.getAnesthesiaWayCode());
        controlReportEntity.setAnesthesiaWayName(controlReportEntityRequest.getAnesthesiaWayCode());
        controlReportEntity.setNotchGrade(controlReportEntityRequest.getOperationIncisionDescription());
        controlReportEntity.setHealingGrade(controlReportEntityRequest.getOperationIncisionHealLevel());
        //处置赋值
        controlReportEntity.setTreatmentName(controlReportEntityRequest.getItemName());
        controlReportEntity.setTreatmentTime(controlReportEntityRequest.getApplicationTime());
    }

    /**
     * 答案列表 带分页
     *
     * @param req
     * @return
     */
    @Override
    public BaseResponse<QueryEditorUserInfoListResponse> list(EditorUserInfo req) {
//		PageHelper.startPage(req.getPageNo(), req.getPageSize());


        QueryEditorUserInfoListResponse queryEditorUserInfoListResponse = new QueryEditorUserInfoListResponse();
        if (CommonUtils.isNotNull(req.getAnswers())) {
            List<String> userInfoIdList = new ArrayList<>();
            List<String> userInfoIds = new ArrayList<>();
            for (EditorAnswer answers : req.getAnswers()) {
                for (EditorAnswer answersList : answers.getAnswersList()) {
                    userInfoIdList = editorUserInfoDAO.queryEditorUserInfo1(answersList, userInfoIdList);
                    if (userInfoIdList.size() == 0) {
                        break;
                    }
                }
                userInfoIds.addAll(userInfoIdList);
                userInfoIdList = new ArrayList<>();
            }
            if (userInfoIds.size() == 0) {
                userInfoIds.add("不存在");
            }
            logger.info(String.valueOf(userInfoIds));
            req.setUserInfoIdList(userInfoIds);
        }

        List<EditorUserInfo> editorUserInfos = editorUserInfoDAO.queryEditorUserInfoList(req);
        queryEditorUserInfoListResponse.setList(editorUserInfos);
        queryEditorUserInfoListResponse.setTotal(editorUserInfoDAO.queryEditorUserInfoCount(req));
        BaseResponse<QueryEditorUserInfoListResponse> baseResponse = new BaseResponse<>();
        baseResponse.setData(queryEditorUserInfoListResponse);
        return baseResponse;
    }

    /**
     * 答案列表 导出
     *
     * @param req
     * @return
     */
    @Override
    public List<EditorUserInfo> listAll(EditorUserInfo req) {

        return editorUserInfoDAO.queryEditorUserInfoByQId(req.getQuestionnaireId());
    }


    @Override
    public BaseResponse queryQuestionnaireAnswerList(EditorQuestionnaireTitle docQuestionnaireListReq) {

        QueryAnswerListResponse queryAnswerListResponse = new QueryAnswerListResponse();

        queryAnswerListResponse.setList(editorAnswerDAO.queryEditorQuestionnaireAnswerList(docQuestionnaireListReq.getQuestionnaireId(), docQuestionnaireListReq.getTitleId()));
        queryAnswerListResponse.setTotal(editorAnswerDAO.queryEditorAnswerCount(docQuestionnaireListReq.getQuestionnaireId(), docQuestionnaireListReq.getTitleId()));
        BaseResponse<QueryAnswerListResponse> baseResponse = new BaseResponse<>();
        baseResponse.setData(queryAnswerListResponse);
        return baseResponse;
    }
}


